<#assign classNameLower = ClassName ? uncap_first>
<template>
	<div>
		<SearchHeader :search="search" @handlerSearch="handlerSearch">
		</SearchHeader>
		<TableCom
			ref="tableCom"
			url="/${classNameLower}"
			@handlerOperate="handlerOperate"
			:tableColumns="tableColumns"
			:tableOperate="tableOperate"
			:isTableIndex="true"
			:operateWidth="200"
		>
		</TableCom>
	</div>
</template>
<script>
export default {
	data () {
		return {
			search : {
				// 搜索
				loading : false,
				form : [
				<#list table.columns as column>
					{
						type : 'text',
						label : '${column.columnComment}:',
						placeholder : '请输入${column.columnComment}',
						key : '${column.columnName2}'
					},
				</#list>
				],
				operates : [
					{
						type : 'search',
						color : 'primary',
						icon : 'el-icon-search',
						name : '查询'
					},
					{
						type : 'add',
						color : 'primary',
						icon : 'el-icon-circle-plus-outline',
						name : '新增'
					}
				]
			},
			tableColumns : [
				// 表头
				<#list table.columns as column>
				{ name : '用户${column.columnComment}', key : '${column.columnName2}' },
				</#list>
			],
			tableOperate : [
				// 操作
				{
					name : '查看',
					type : 0,
					color : 'warning',
					role : [],
					icon : 'el-icon-view'
				},
				{
					name : '修改',
					type : 1,
					color : 'primary',
					role : [],
					icon : 'el-icon-edit'
				}
			],
			dialogForm : [
				<#list table.columns as column>
				{
					type : 'text',
					label : '${column.columnComment}',
					placeholder : '请输入${column.columnComment}',
					key : '${column.columnName2}',
					rules : [
						{ required : true, message : '请输入${column.columnComment}', trigger : 'blur' }
					]
				},
				</#list>
			]
		};
	},
	methods : {
		// 状态
		activeHandler (row){
			let tip = '';
			if (row.state===0){
				tip = `是否启用?`;
			} else {
				tip = `是否禁用?`;
			}
			this.$confirm(tip, '提示', {
				confirmButtonText : '确定',
				cancelButtonText : '取消',
				type : 'warning'
			}).then(() => {
				this.$notify({
					title : '成功',
					message : '修改成功',
					type : 'success'
				});
			}).catch(() => {
				this.$notify({
					title : '警告',
					message : '取消操作',
					type : 'warning'
				});
			});
		},
		// 搜索
		handlerSearch (types, data) {
			if (types.type === 'add'){
				this.$dialogForm.open({
					config : {
						title : '新增',
						leftButText : '取消',
						isRightBut : true
					},
					disabledAll : false,
					dialogForm : this.dialogForm,
					handlerFn : this.handlerUpdate
				});
			} else {
				this.search.loading = true;
				this.$refs.tableCom.fetchData(
					{
						pageNum : 1,
						pageSize : 100
					},
					data,
					() => {
						this.search.loading = false;
					}
				);
			}
		},
		// dialogForm操作
		handlerUpdate (parameMap, callback) {
			console.log(parameMap);
			setTimeout(() => {
				callback();
			}, 3000);
		},
		// 操作项
		handlerOperate (operateItem, data) {
			switch (Number(operateItem.type)) {
			case 0:
				this.$dialogForm.open({
					config : {
						title : '查看',
						leftButText : '关闭',
						isRightBut : false
					},
					disabledAll : true,
					dialogForm : this.dialogForm,
					handlerFn : null,
					result : data
				});
				break;
			case 1:
				this.$dialogForm.open({
					config : {
						title : '修改',
						leftButText : '取消',
						isRightBut : true
					},
					disabledAll : false,
					dialogForm : this.dialogForm,
					handlerFn : this.handlerUpdate,
					result : data
				});
				break;
			}
		}
	}
};
</script>
<style lang="scss" scoped></style>
